/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2025. All rights reserved.
 *
 */

/**
 * config.json中module type
 *
 * @since 2022/2/25
 */
import { OhosLogger } from '../utils/log/ohos-logger.js';

const _log = OhosLogger.getLogger('ModuleType');

export enum ModuleType {
  Entry = 'entry',
  Feature = 'feature',
  Har = 'har',
  Shared = 'shared',
}

/**
 * 为枚举类型ModuleType附加方法
 *
 * @since 2022/2/25
 */
export namespace ModuleType {
  export function valueOf(moduleTypeStr: string): ModuleType {
    switch (moduleTypeStr) {
      case 'entry':
        return ModuleType.Entry;
      case 'feature':
        return ModuleType.Feature;
      case 'har':
        return ModuleType.Har;
      case 'shared':
        return ModuleType.Shared;
      default:
        _log.printErrorExit(
          'INVALID_MODULE_TYPE_VALUE',
          [moduleTypeStr]
        );

        // avoid ts-ignore
        return ModuleType.Entry;
    }
  }
}

/**
 * moduleType的string类型转换为枚举类型
 *
 * @param str 模块类型
 * @return ModuleType 返回枚举
 */
export function mapStringToModuleTypeEnum(str: string): ModuleType | undefined {
  switch (str) {
    case 'hap':
      return ModuleType.Feature;
    case 'har':
      return ModuleType.Har;
    case 'hsp':
      return ModuleType.Shared;
    default:
      return undefined;
  }
}
